home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / CD32 / CD32-Tools / cdmpeg-110 / ILBMSupport.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-27  |  6.1 KB  |  264 lines

  1. /**************
  2.  
  3.     ILBMSupport.c
  4.  
  5. ***************/
  6.  
  7. /*
  8.  * COPYRIGHT: Unless otherwise noted, all files are Copyright (c) 1993-1999
  9.  * Amiga, Inc.  All rights reserved.
  10.  *
  11.  * DISCLAIMER: This software is provided "as is".  No representations or
  12.  * warranties are made with respect to the accuracy, reliability, performance,
  13.  * currentness, or operation of this software, and all use is at your own risk.
  14.  * Neither Amiga nor the authors assume any responsibility or liability
  15.  * whatsoever with respect to your use of this software.
  16.  */
  17.  
  18. // Tab size is 8!
  19.  
  20.  
  21. #include "iffp/ilbmapp.h"
  22.  
  23. #include "disp_def.h"
  24. #include "retcodes.h"
  25.  
  26. #include "debugsoff.h"
  27.  
  28. // Uncomment to get debug output turned on
  29. #define KPRINTF
  30. //#include "debugson.h"
  31.  
  32.  
  33. IMPORT struct Library        * GfxBase;
  34.  
  35.  
  36. #define    ILBMINFO struct ILBMInfo
  37.  
  38. /* ILBM Property chunks to be grabbed
  39.  * List BMHD, CMAP and CAMG first so we can skip them when we write
  40.  * the file back out (they will be written out with separate code)
  41.  */
  42. LONG ilbmprops[] = 
  43. {
  44.     ID_ILBM, ID_BMHD,
  45.     ID_ILBM, ID_CMAP,
  46.     ID_ILBM, ID_CAMG,
  47.     ID_ILBM, ID_CCRT,
  48.     ID_ILBM, ID_AUTH,
  49.     ID_ILBM, ID_Copyright,
  50.     TAG_DONE
  51. };
  52.  
  53. // ILBM Collection chunks (more than one in file) to be gathered
  54. LONG ilbmcollects[] =
  55. {
  56.     ID_ILBM, ID_CRNG,
  57.     TAG_DONE
  58. };
  59.  
  60. // ILBM Chunk to stop on
  61. LONG ilbmstops[] =
  62. {
  63.     ID_ILBM, ID_BODY,
  64.     TAG_DONE
  65. };
  66.  
  67.  
  68. /* queryilbm
  69.  *
  70.  * Passed an initilized ILBMInfo with a not-in-use IFFHandle,
  71.  *   and a filename,
  72.  *   will open an ILBM, fill in ilbm->camg and ilbm->bmhd,
  73.  *   and close the ILBM.
  74.  *
  75.  * This allows you to determine if the ILBM is a size and
  76.  *   type you want to deal with.
  77.  *
  78.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  79.  */
  80.  
  81. // query just wants these chunks
  82. LONG queryprops[] =
  83. {
  84.     ID_ILBM, ID_BMHD,
  85.     ID_ILBM, ID_CAMG,
  86.     TAG_DONE
  87. };
  88.  
  89. // scan can stop when a CMAP or BODY is reached
  90. LONG querystops[] =
  91. {
  92.     ID_ILBM, ID_CMAP,
  93.     ID_ILBM, ID_BODY,
  94.     TAG_DONE
  95. };
  96.  
  97.  
  98. LONG
  99. queryilbm( ILBMINFO *ilbm, UBYTE *filename )
  100. {
  101.     LONG error = 0L;
  102.     BitMapHeader *bmhd;
  103.  
  104.     if ( !ilbm->ParseInfo.iff )
  105.     return(CLIENT_ERROR);
  106.  
  107.     if ( !(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)) ) {
  108.     D(PRINTF("queryilbm: openifile successful\n"));
  109.  
  110.     error = parseifile((struct ParseInfo *)ilbm,
  111.         ID_FORM, ID_ILBM,
  112.         ilbm->ParseInfo.propchks,
  113.         ilbm->ParseInfo.collectchks,
  114.         ilbm->ParseInfo.stopchks);
  115.  
  116.     D(PRINTF("queryilbm: after parseifile, error = %ld\n",error));
  117.  
  118.     if ( (!error) || (error == IFFERR_EOC) || (error == IFFERR_EOF) ) {
  119.         if ( contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM) ) {
  120.  
  121.         if(bmhd = (BitMapHeader*) findpropdata(ilbm->ParseInfo.iff,ID_ILBM,ID_BMHD)) {
  122.             *(&ilbm->Bmhd) = *bmhd;
  123.             ilbm->camg = getcamg(ilbm);
  124.         } else {
  125.             error = NOFILE;
  126.         }
  127.         } else {
  128.         message(SI(MSG_ILBM_NOILBM));
  129.         error = NOFILE;
  130.         }
  131.     }
  132.     closeifile( (struct ParseInfo *)ilbm );
  133.     }
  134.  
  135.     return(error);
  136.  
  137. } // queryilbm()
  138.  
  139.  
  140. DoQuery( UBYTE * filename, DISP_DEF * disp_def )
  141. {
  142.     ILBMINFO    * ilbm;
  143.     LONG      error = FALSE;
  144.  
  145.  
  146.     if (ilbm = (ILBMINFO *)AllocMem(sizeof(ILBMINFO),MEMF_PUBLIC|MEMF_CLEAR)) {
  147.  
  148.     ilbm->ParseInfo.propchks    = ilbmprops;
  149.     ilbm->ParseInfo.collectchks    = ilbmcollects;
  150.     ilbm->ParseInfo.stopchks    = ilbmstops;
  151.  
  152.     if( ilbm->ParseInfo.iff = AllocIFF() ) {
  153.         if( !(error = queryilbm(ilbm,filename))) {
  154.  
  155.         D(PRINTF("DoQuery: after query, this ILBM is %ld x %ld x %ld, PageWidth= %ld,  modeid=$%lx\n",
  156.         ilbm->Bmhd.w, ilbm->Bmhd.h, ilbm->Bmhd.nPlanes, ilbm->Bmhd.pageWidth, ilbm->camg);)
  157.  
  158.         disp_def->Width = disp_def->NominalWidth = MAX(ilbm->Bmhd.pageWidth, ilbm->Bmhd.w);
  159.         disp_def->Height = disp_def->NominalHeight = MAX(ilbm->Bmhd.pageHeight,ilbm->Bmhd.h);
  160.         disp_def->Depth = MIN(ilbm->Bmhd.nPlanes,MAXAMDEPTH);
  161.  
  162.         D(PRINTF("DoQuery: RowBytes= %ld, disp_def->Width= %ld, Height= %ld, Depth= %ld\n",
  163.             RowBytes( disp_def->Width ),disp_def->Width,disp_def->Height,disp_def->Depth);)
  164.  
  165.         if ( !(disp_def->Flags & DISP_XLMODEID) )
  166.             disp_def->ModeID = ilbm->camg;
  167.         }
  168.         FreeIFF(ilbm->ParseInfo.iff);
  169.     }
  170.  
  171.     FreeMem( ilbm, sizeof(ILBMINFO) );
  172.     }
  173.  
  174.     return( !error );
  175.  
  176. } // DoQuery()
  177.  
  178.  
  179. DoILBM( UBYTE * filename, DISP_DEF * disp_def )
  180. {
  181.     ILBMINFO        * ilbm;
  182.     BitMapHeader    * bmhd;
  183.     LONG          error = FALSE;
  184.  
  185.     D(PRINTF("DoILBM 1 bm[0]= 0x%lx, bm[1]= 0x%lx\n",disp_def->bm[0],disp_def->bm[1]);)
  186.  
  187.     if (ilbm = (ILBMINFO *)AllocMem(sizeof(ILBMINFO),MEMF_CLEAR)) {
  188.  
  189.     D(PRINTF("DoILBM 2\n");)
  190.  
  191.     ilbm->vp = disp_def->vp;
  192.     ilbm->ParseInfo.propchks    = ilbmprops;
  193.     ilbm->ParseInfo.collectchks = ilbmcollects;
  194.     ilbm->ParseInfo.stopchks    = ilbmstops;
  195.  
  196.     if( ilbm->ParseInfo.iff = AllocIFF() ) {
  197.  
  198.         D(PRINTF("DoILBM 3\n");)
  199.  
  200.         if ( !(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)) ) {
  201.  
  202.         D(PRINTF("DoILBM 4\n");)
  203.  
  204.         error = parseifile((struct ParseInfo *)ilbm,
  205.             ID_FORM, ID_ILBM,
  206.             ilbm->ParseInfo.propchks,
  207.             ilbm->ParseInfo.collectchks,
  208.             ilbm->ParseInfo.stopchks);
  209.  
  210.         if ( (!error) || (error == IFFERR_EOC) || (error == IFFERR_EOF) ) {
  211.  
  212.             D(PRINTF("DoILBM 5\n");)
  213.  
  214.             if ( contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM) ) {
  215.  
  216.             D(PRINTF("DoILBM 6\n");)
  217.  
  218.             if(bmhd = (BitMapHeader*) findpropdata(ilbm->ParseInfo.iff,ID_ILBM,ID_BMHD)) {
  219.                 D(PRINTF("DoILBM 7\n");)
  220.  
  221.                 *(&ilbm->Bmhd) = *bmhd;
  222.                 ilbm->camg = getcamg(ilbm);
  223.                 error = loadbody(ilbm->ParseInfo.iff, disp_def->bm[0], &ilbm->Bmhd);
  224.             } else  {
  225.                 error = NOFILE;
  226.             }
  227.  
  228.             D(PRINTF("DoILBM 8 error= %ld, bm[0]= 0x%lx\n",error,disp_def->bm[0]);)
  229.  
  230.             if(!error) {
  231.                 D(PRINTF("DoILBM 9\n");)
  232.  
  233.                 if( !(disp_def->Flags & DISP_XLPALETTE) && !getcolors(ilbm) ) {
  234.                 D(PRINTF("DoILBM A\n");)
  235.  
  236.                 setcolors(ilbm,disp_def->vp);
  237.                 freecolors(ilbm);
  238.                 }
  239.  
  240.                 if ( disp_def->bm[0] && disp_def->bm[1] ) {
  241.                 BltBitMap( disp_def->bm[0],0,0,disp_def->bm[1],
  242.                  0,0,disp_def->Width,disp_def->Height,0xC0,0xFF,NULL);
  243.                 }
  244.             }
  245.  
  246.             } else {
  247.             message(SI(MSG_ILBM_NOILBM));
  248.             error = NOFILE;
  249.             }
  250.             }
  251.             closeifile( (struct ParseInfo *)ilbm );
  252.         }
  253.  
  254.         FreeIFF(ilbm->ParseInfo.iff);
  255.     }
  256.  
  257.     FreeMem( ilbm, sizeof(ILBMINFO) );
  258.     }
  259.  
  260.     return( error );
  261.  
  262. } // DoILBM()
  263.  
  264.